package com.example.app.pages.main.home.addNew.addRecord

import androidx.compose.foundation.layout.width
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.app.components.MyChip.MyChip
import com.example.app.components.MyModalBottomSheet.MyModalBottomSheetDateTimePicker.MyDateTimeSwitchBtnState
import com.example.app.components.MyModalBottomSheet.MyModalBottomSheetDateTimePicker.MyModalBottomSheetDateTimePicker
import com.example.app.components.MyModalBottomSheet.MyModalBottomSheetDateTimePicker.MyModalBottomSheetDateTimePickerState
import com.example.app.components.MySpacer.MySpacer
import com.example.app.components.MyText.MyText
import com.example.app.ui.theme.formatDatePattern
import com.example.app.ui.theme.formatTimePattern
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.TimeZone

var myModalBottomSheetDateTimePickerState = MyModalBottomSheetDateTimePickerState()
var myDateTimeSwitchBtnState = MyDateTimeSwitchBtnState()
@OptIn(
    ExperimentalMaterialApi::class,
    ExperimentalMaterial3Api::class
)
@Composable
fun IncomeToolListDatePicker() {
    var scope = rememberCoroutineScope()
    var calNow = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"))
    var timeInMillis by remember {
        mutableStateOf(calNow.timeInMillis)
    }
    MyModalBottomSheetDateTimePicker(myModalBottomSheetDateTimePickerState = myModalBottomSheetDateTimePickerState,
        myDateTimeSwitchBtnState = myDateTimeSwitchBtnState,
        initDateTime = timeInMillis,
        onConfirm = {
            timeInMillis = it.timeInMillis
        })
    MySpacer(modifier = Modifier.width(12.dp))
    MyChip(onClick = {
        //每次打开，默认定位到日期选择，不是时间选择
        myDateTimeSwitchBtnState.flowUpdate_checked(false)
        //显示bottomSheet
        myModalBottomSheetDateTimePickerState.flowUpdate_visible(true)
    }) {
        MyText(text = SimpleDateFormat("${formatDatePattern} ${formatTimePattern}").format(timeInMillis))
    }
}